package com.ysf.cn.springbootshrio.controller;

import com.ysf.cn.springbootshrio.pojo.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author ysf
 * @date 2020/2/13 15:13
 */
@Controller
public class IndexController {

    /**
     * 首页,并将登陆用户的全名返回前台
     * @param model
     * @return
     */
    @RequestMapping(value = {"/","/index"},method = RequestMethod.GET)
    public String index(Model model){
        User user= (User) SecurityUtils.getSubject().getPrincipal();
        //model.addAttribute("userName",user.getFullname());
        return "admin/index";
    }

    /**
     * 跳转新增
     * @return
     */
    @RequestMapping(value = "user/adds",method = RequestMethod.POST)
    public String add(){
        return "user/add";
    }

    /**
     * 跳转更新
     * @return
     */
    @RequestMapping(value = "user/updates",method = RequestMethod.GET)
    //
    //@RequiresPermissions(value = {"update"},logical = Logical.OR)
    public String update(){
        System.out.println("用户更新");
        return "user/update";
    }

    /**
     * 跳转未经授权页面
     * @return
     */
    @RequestMapping(value = "/unauth",method = RequestMethod.GET)
    public String unauth(){
        return "error/unauthorized";
    }


}
